try:
    from collections.abc import Sequence
except ImportError:
    from collections import Sequence

class Input(object):
    def __init__(self, action, **kwargs):
        # if action not in self.actions:
        #     raise ValueError("Invalid action type.")
        self.action = action
        self.args = kwargs

    def __getattr__(self, item):
        if 'args' in self.__dict__ and item in self.args:
            return self.args[item]
        raise AttributeError('No such attribute.')


class UserInput(Input):
    actions = ["QUIT", "MOVE", "RESTART", "CHANGE_DIRECTION", "ACTIVATE_TURBO"]


class AiInput(Input):
    actions = ["MOVE", "CHANGE_DIRECTION"]


class ChangeDirection(Input):
    def __init__(self, entity, direction=None):
        super(ChangeDirection, self).__init__("CHANGE_DIRECTION")
        self.entity = entity
        self.direction = direction


class ActivateTurbo(Input):
    def __init__(self, entity):
        super(ActivateTurbo, self).__init__("ACTIVATE_TURBO")
        self.entity = entity


class Direction(Sequence):
    def __init__(self, x, y, name):
        self.x = x
        self.y = y
        self.name = name

    def __len__(self):
        return 2

    def __getitem__(self, item):
        if item == 0:
            return self.x
        elif item == 1:
            return self.y
        else:
            raise IndexError('Directions have only two components.')

    def __eq__(self, other):
        return tuple(self) == tuple(other)

    def __hash__(self):
        return int('SJAMCS', 36) ^ hash(tuple(self))


NORTH = Direction(0, -1, 'north')
SOUTH = Direction(0, 1, 'south')
EAST = Direction(1, 0, 'east')
WEST = Direction(-1, 0, 'west')


# event = UserInput("MOVE", entity=player, direction=NORTH)
